<template>
    <div>
        <h1>登录</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">用户名</td>
                    <td><input type="text" v-model="info.username"></td>
                </tr>
                <tr>
                    <td align="right">密码</td>
                    <td><input type="password" v-model="info.userpwd"></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="登录" class="btn btn-info" @click="moneylogin"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from "vue";
import axios from 'axios'
import moment from 'moment'
import { useStore } from "@/stores/user";
import {useRouter,useRoute} from "vue-router";
const router=useRouter();
const route=useRoute();
const usestore=useStore();
let info:any=reactive({
    username:"",
    userpwd:""
})
const moneylogin=()=>
{
    if(info.username=="")
    {
        alert("用户名不能为空");
        return;
    }
    if(info.userpwd=="")
    {
        alert("密码不能为空");
        return;
    }
    axios({
        url:'http://localhost:5182/api/Money/Login',
        method:'post',
        params:info
    })
    .then((res)=>
    {
        console.log(res);
        if(res.data==-1)
        {
            alert("用户名不存在");
            return;
        }
        if(res.data==-2)
        {
            alert("密码不正确");
            return;
        }
        
            alert("登录成功");
            usestore.userInfo=res.data;
            router.push("/show");
            return;
        
        
    })
    .catch((err)=>
    {
        console.log(err);
    })
}
</script>

<style scoped>

</style>